# Maintainer: Alexey Pavlov <Alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=mako
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.2.4
pkgrel=2
pkgdesc="A super-fast templating language that borrows the best ideas from the existing templating languages (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=('spdx:MIT')
url="https://www.makotemplates.org/"
depends=("${MINGW_PACKAGE_PREFIX}-python-markupsafe"
         "${MINGW_PACKAGE_PREFIX}-python-beaker")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-nose")
options=('staticlibs')
source=("https://pypi.org/packages/source/M/Mako/Mako-${pkgver}.tar.gz")
sha256sums=('d60a3903dc3bb01a18ad6a89cdbe2e4eadc69c0bc8ef1e3773ba53d44c3f7a34')

prepare() {
  cd "${srcdir}"
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py test || true
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1

  # fix python command in files
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    # Remove shebang line
    sed -e '1 { s/^#!.*$// }' -i "${_f}"
  done

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/COPYING"
}
